package com.imc.api.attence.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.imc.api.attence.pojo.Sign;
import com.imc.api.attence.service.SignService;
import com.twp.common.component.process.exception.combo.IComboExecptionForTFunc;
import com.twp.common.tuple.ResultDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;
import java.util.Map;

/*
 * 类描述：签到管理
 * 开发者：tanweiping
 * 创建日期：2018/10/28 20:37
 */
@RestController
@RequestMapping("/api/sign")
public class SignController {

    @Autowired
    IComboExecptionForTFunc iComboExecptionForTFunc;

    @Autowired
    SignService signService;//签到服务类

    /**
     * QY 2018/9/3 8:01
     * 方法描述：传参对象
     **/
    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    public static class ReqTuple {
        Map <String, String> parmsMap;
    }

    /*
     * YT  2018/10/28 20:38
     * 方法描述：通过课程ID查询学生信息
     */
    @GetMapping("/getStudentByLessonId")
    ResultDTO getStudentByLessonId(String lessonId, String schduleId) {

        return iComboExecptionForTFunc.executeFlow(
                ResultDTO.builder().build(),
                t -> {
                    t.setData(signService.getStudentByLessonId(schduleId));
                },
                (e, t) -> {
                    e.printStackTrace();
                    t.setIsSuccess(false);
                    t.setMessage("获取失败");
                }
        );
    }

    /*
     * YT  2018/10/28 20:39
     * 方法描述：发起签到
     */
    @PostMapping("")
    ResultDTO postSign(String schduleId, @RequestBody List <Sign> signList, Principal principal) {
        return iComboExecptionForTFunc.executeFlow(
                ResultDTO.builder().message("签到成功").build(),
                t -> {
                    signService.postAndPutSign(schduleId, signList, principal);
                },
                (e, t) -> {
                    t.setIsSuccess(false);
                    t.setMessage("签到失败");
                }
        );
    }
}